package com.deanlib.cabinet.utils;

import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Locale;

import static com.deanlib.plantern.utils.FileUtils.isDownloadsDocument;
import static com.deanlib.plantern.utils.FileUtils.isExternalStorageDocument;
import static com.deanlib.plantern.utils.FileUtils.isGooglePhotosUri;
import static com.deanlib.plantern.utils.FileUtils.isMediaDocument;

import com.deanlib.cabinet.data.model.Resource;
import com.deanlib.plantern.utils.FileUtils;

/**
 * Created by Dean on 2022/7/5
 */
public class FileUtilsExt {

    public static FileAttr getFileAttr(File file) throws IOException {
        FileAttr fileAttr = null;
        if (file!=null && file.isFile()){
            BasicFileAttributes basicFileAttributes = Files.readAttributes(Paths.get(file.getAbsolutePath()), BasicFileAttributes.class);
            long createTime = basicFileAttributes.creationTime().toMillis();
            long size = basicFileAttributes.size();

        }
        return fileAttr;
    }

    static class FileAttr{

    }

    public static boolean isImage(String mineType){
        return mineType.startsWith("image/");
    }

    public static boolean isVideo(String mineType){
        return mineType.startsWith("video/");
    }

    public static boolean saveFileByStream(InputStream in, String savePath){
        boolean b = false;
        OutputStream out = null;
        try {
            out = new FileOutputStream(savePath);
            int len = 0;
            byte[] buffer = new byte[1024*1024*6];
            while ((len=in.read(buffer))!=-1){
                out.write(buffer, 0, len);
                out.flush();
            }
            b = true;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }
        return b;
    }
}
